<form id="userRoleForm" class="form-horizontal" action="${ctx}/user/saveUserRole.do" method="post">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h5 class="blue">设置角色权限</h5>
    </div>
    <input type="hidden" name="roleId" id="roleId" class="col-xs-12 col-sm-4 required" value="${role.id!}"/>

    <div class="modal-body">
        <div class="form-group">
            <div id="rescTree" class="ztree"></div>
        </div>



        <div class="modal-footer center">
            <button type="button" class="btn btn-sm" data-dismiss="modal"><i class="ace-icon fa fa-times"></i> 关闭
            </button>
        </div>
    </div>
</form>
<script src="${ctx}/static/admin/assets/js/jquery.validate.js"></script>
<script src="${ctx}/static/admin/assets/js/jquery.validate.messages_zh.js"></script>
<script src="${ctx}/static/admin/assets/js/jquery.ztree.all-3.5.min.js"></script>
<link rel="stylesheet" href="${ctx}/static/admin/assets/css/zTreeStyle/zTreeStyle.css" type="text/css">

<script type="text/javascript">
    $(document).ajaxStart($.blockUI()).ajaxStop($.unblockUI());
    $(document).ready(function () {

        // 权限树
        var setting = {
            view: {
                dblClickExpand: true,
                showIcon: false
            },
            data: {
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "pid",
                    rootPId: 0
                }
            },
            check: {
                enable: true,
                chkStyle: "checkbox",
                chkboxType: {"Y": "", "N": ""},
                autoCheckTrigger: true
            },
            callback: {
                onCheck: onCheckHandler
            }
        }


        $("#resc").click(function () {
            $.get("${ctx}/role/getResourceTree.do?id=${role.id!}", function (data) {
                $.fn.zTree.init($("#rescTree"), setting, data.data);
            });
        });
    });
    //权限树 相关事件
    function onCheckHandler(event, treeId, treeNode) {
        if (treeNode.checked) {
            // 增加权限
            $.post("${ctx}/role/addRoleResource.do", {"roleId": "${role.id!}", "resId": treeNode.id});
        }
        else {
            // 移除权限
            $.post("${ctx}/role/deleteRoleResource.do", {"roleId": "${role.id!}", "resId": treeNode.id});
        }
    }


</script>